from pymysql.converters import escape_string
import  pymysql
import time
# 连接mysql

db = pymysql.connect(host='rds637zp6c38m5952l72n.mysql.rds.aliyuncs.com', port=3306, user='ghsadmin', passwd='123QWEasd', db='test_ghsmall')
#db = pymysql.connect(host='12.18.0.18', port=3306, user='archery', passwd='ghstestarchery', db='archery')
# 获取mysql操作光标
sql_cursor = db.cursor()
sql_cursor_2 = db.cursor()
bn_sql='''
SELECT bn from  ghs_goods_search_new  WHERE is_jd=1 AND marketable=1 LIMIT 2;
'''
sql_cursor_2.execute(bn_sql)
res_info = sql_cursor_2.fetchall()
res = []
for val1 in res_info:
    for val2 in val1:
        res.append(val2)
print(res)
start_time = time.time()
for i in res:
    print(i)
    update_sql = '''
    UPDATE ghs_goods_search_new SET jd_store_bj = 1, jd_store_sh = 1 , jd_store_dl = 1, jd_store_tj = 1, jd_store_jn = 1 , jd_store_cd = 1 ,is_jd = 1 WHERE bn = '%s';
    ''' %(i)
    select_sql_3 = 'commit;'
    sql_cursor.execute(update_sql)
    sql_cursor.execute(select_sql_3)
end_time = time.time()
print("程序执行了%f秒"%(end_time - start_time))

#程序执行了212.215478秒   471